package etools

import (
    "net"
    "strings"
)

func GetInterfaceIp(name string) []string {
    list := make([]string, 0)

    interface_list, err := net.Interfaces()
    if err != nil {
        return list 
    }

    for _, i := range interface_list {
        if i.Name == name {
            addrList, err := i.Addrs()
            if err != nil {
                continue
            }

            for _, addr := range addrList {
                addrs := strings.SplitN(addr.String(), "/", 2)
                list = append(list, addrs[0])
            }

            break
        }
    }

    return list
}
